package com.bsoft.hospitalchs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bsoft.hospitalchs.R;
import com.bsoft.hospitalchs.model.ChildCaseRes;

import java.util.List;

/**
 * Created by 泅渡者
 * Created on 2017/6/14.
 */

public class ChildCaseAdapter extends RecyclerView.Adapter<ChildCaseAdapter.ViewHolder> {

    private Context context;
    private List<ChildCaseRes.BodyBean> dataList;

    public interface OnItemClickLitener {
        void onItemClick(View view, int potison);
    }

    private ChildCaseAdapter.OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(ChildCaseAdapter.OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;

    }


    public ChildCaseAdapter(Context context, List<ChildCaseRes.BodyBean> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public ChildCaseAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.recycle_case_item, parent, false));
//        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycle_case_item, parent, false);
//        return new ChildCaseAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(final ChildCaseAdapter.ViewHolder holder, final int position) {
        holder.tv_doctor.setText(dataList.get(position).getDOCTORNAME());
        holder.tv_time.setText(dataList.get(position).getVISITTIME());
        holder.tv_yueling.setText(dataList.get(position).getEXACTAGE());

        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mOnItemClickLitener.onItemClick(holder.itemView, position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        private TextView tv_doctor;
        private TextView tv_yueling;
        private TextView tv_time;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_doctor = (TextView) itemView.findViewById(R.id.tv_doctor);
            tv_yueling = (TextView) itemView.findViewById(R.id.tv_yueling);
            tv_time = (TextView) itemView.findViewById(R.id.tv_time);

        }
    }

    public void addAllData(List<ChildCaseRes.BodyBean> dataList) {
        for (ChildCaseRes.BodyBean bodyBean:dataList){
            this.dataList.add(bodyBean);
        }
        notifyDataSetChanged();
    }

    public void clearData() {
        this.dataList.clear();
        notifyDataSetChanged();
    }
    public ChildCaseRes.BodyBean  getCurrentItem(int position){
        return dataList.get(position);
    }
}
